package com.controller;


import com.domain.DTO.FlightInfoDto;
import com.domain.VO.BestFlightChoseRoleVo;
import com.domain.VO.FlightInfoVO;
import com.domain.assembler.FlightAssembler;
import com.domain.DTO.FlightDto;
import com.domain.VO.FlightChoseRoleVo;
import com.service.IFlightInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import com.common.result.ResponseResultAdvice;
import org.springframework.validation.annotation.Validated;

import java.util.List;

/**
 * @author 大忽悠
 * @create 2022/9/15 11:09
 */
@Validated
@RestController
@RequestMapping("/flight")
@RequiredArgsConstructor
@ResponseResultAdvice
@Api(tags="航班请求")
public class FlightController {
    private final FlightAssembler flightAssembler;
    private final IFlightInfoService iFlightInfoService;

    @ApiOperation("添加新航班")
    @PostMapping
    public void addFlight(FlightInfoVO flightInfoVO){
         flightInfoVO.insertCheck();
         iFlightInfoService.save(flightInfoVO);
    }

    @ApiOperation("删除航班")
    @DeleteMapping
    public void removeFlight(@RequestParam("id")Integer id){
          iFlightInfoService.removeById(id);
    }

    @ApiOperation("根据用户要求筛选符合规则的航班")
    @GetMapping("/filterFlightByUserRole")
    public List<FlightInfoDto> filterFlightByUserRole(FlightChoseRoleVo flightChoseRoleVo) {
          return flightAssembler.filterFlightByChoseRole(flightChoseRoleVo);
    }

    @ApiOperation("根据用户要求筛选出最佳行程")
    @GetMapping("/filterBestRouter")
    public FlightInfoDto filterBestRouter(BestFlightChoseRoleVo bestFlightChoseRoleVo) {
        return flightAssembler.filterBestRouter(bestFlightChoseRoleVo);
    }
}
